package com.hera.base.util;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

import com.vaadin.ui.Component;

public class VaadinUtil {

	public static void aplicarReflexionId(Component component) {
		Field[] fields = component.getClass().getDeclaredFields();
		for (Field variable : fields) {
			try {
				boolean isAccess = variable.isAccessible();
				if (!isAccess) {
					variable.setAccessible(!isAccess);
				}				
				Object objeto = variable.get(component);
				if(objeto instanceof Component){
					Method metodo =objeto.getClass().getMethod("setId",String.class);
					metodo.invoke(objeto, variable.getName());	
				}			
				variable.setAccessible(isAccess);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}
